
$(document).ready(function(){
	//$('#createdDate').datepicker('option', {dateFormat: "yy-mm-dd" } ); 
	$('#createdDate').datepicker( { dateFormat: 'yy-mm-dd', changeYear: true } ); 

   $("#addShopForm").validate({

        rules: {      
            url: { required: true, url: true, maxlength: 200},   
            vcode: {required: true}
         },
         messages: {
            url: { required:"链接不能为空", url:"链接格式不正确", maxlength: "最大长度不超过200字符"},       
            vcode: {required:"验证码不能为空，请输入验证码"}             
         },
         submitHandler: function(form) {
            return true;
         }
     });
     
     
   if($("#province").length>0)
    	 LoadLocation($("#province").val(),$("#city").val());
    	     
   $("#addShopForm2").validate({
	
	        rules: {      
	            shopName: { required: true, maxlength: 200},   
	            nickName: {required: true, maxlength: 40},
	            logoURL: {maxlength: 200},
	            createdDate: { dateISO: true, maxlength: 10},
	            shopCategory: {required: true}
	            
	         },
	         messages: {
	            shopName: { required:"店铺名称不能为空", maxlength: "最大长度不超过200字符"},   
	            nickName: { required:"掌柜不能为空", maxlength: "最大长度不超过40字符"},  
	            logoURL: { maxlength: "最大长度不超过200字符"},  
	            createdDate: { dateISO:"日期格式不正确，如2010-01-30", maxlength: "最大长度不超过10字符"},   
	            shopCategory: {required:"店铺类别不能为空"}     
	         },
	         submitHandler: function(form) {
	            return true;
	         }
     });

     
	$("#sToogle a").toggle(function(){
		$("#shopDes").css({"height":"auto", "overflow":"auto", "overflow-x":"hidden", "overflow-y":"auto"});
		$(this).parent().css({"background":"url("+edp_static_domain_url+"image/icn_doHide.gif) no-repeat left"});
		$(this).html("[收起]");
	},function(){
		$("#shopDes").css({"height":"0px", "overflow":"hidden", "overflow-y":"hidden"});
		$(this).parent().css({"background":"url("+edp_static_domain_url+"image/icn_doShow.gif) no-repeat left"});
		$(this).html("[全部展开]");
	});     
    
     
});


function previewLogo(){
   	 $("#shop_pre_pic").attr('src',$("#logoURL").val());
}


function refresh_vcode(url){

  $("#vimg").attr('src',url);

}


$(document).ready(function(){
	$("#shopDes img").each(function(){
		var width = 550;
		var image = $(this);
		
	    if(image.width()>width){
	     image.width(width);
	     image.height(width/image.width()*image.height());
	    }   
	});
});	


function previewIntro(){
	
	// the unblockUI plugin can't handle the iframe correctly, so
	// we have to create the block dialogue ourself here.
	$.blockUI("");
	$("#previewFrame").contents().find("body").html( $("#shopDesc").val() );
	$("#previewFrame").css("border" , "none" );
	
	// make it located in the center of the window
	$("#previewWindow").width("800px");
	$("#previewWindow").height( "500px" );
	$("#previewWindow").css("margin-left" , "-400px");
	$("#previewWindow").css( "margin-top", "-250px" );
	$("#previewWindow").css( "display", "block");
	$("#previewWindow").css( "z-index", "9999");
	$("#previewWindow").css("position" , "absolute");
	$("#previewWindow").css("left" , "50%" );
	$("#previewWindow").css("top" , "50%" );
	$("#previewWindow").css("background" , "white" );
	
	
	
}

function closePreview(){
	UnblockUI(100);
	$("#previewWindow").css( "display", "none");
}


function LoadLocation( province, city ){

	var options = $("#selprovince" ).html();
	for ( var key in cityMap ){
		if( key == province )
			options += "<option value='" + key + "' selected>" +  key +"</option>";
		else
			options += "<option value='" + key + "'>" +  key +"</option>";
	}
	
	$("#selprovince").html( options );
	
	$("#selprovince").change(
		function()
		{
			var citys = "<option value=''>选择城市</option>";
			var pro = $("#selprovince option:selected").get(0).value;

			if( pro != '' ){
				for( i = 0; i < cityMap[pro].length; i++ )
				{
					citys += "<option value='" + cityMap[pro][i] + "'>" + cityMap[pro][i] + "</option>";
				}
				$("#selcity").html( citys );
				$("#province").val( pro );
			}
			else{
				$("#selcity").html( citys );
			}
		} 
		);
	$("#selcity").change(
		function()
		{
			$("#city").val( $("#selcity option:selected").get(0).value );
		}
	);

	//init selection
	var curprovince = $("#selprovince option:selected").get(0).value;
	if( curprovince != '' ){
		var citys = "";
		var pro = $("#selprovince option:selected").get(0).value;
		for( i = 0; i < cityMap[pro].length; i++ )
		{
			if( city == cityMap[pro][i] )
				citys += "<option value='" + cityMap[pro][i] + "' selected>" + cityMap[pro][i] + "</option>";
			else
				citys += "<option value='" + cityMap[pro][i] + "'>" + cityMap[pro][i] + "</option>";
		}
		$("#selcity").html( citys );
	}
	//default selection
	else{
		$("#selprovince").val('0');
		$("#selprovince").change();
	}
}
